package com.education.platform.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import com.education.platform.common.Result;
import com.education.platform.dto.teacher.AdminTeacherQueryDTO;
import com.education.platform.dto.teacher.AuditIdentityDTO;
import com.education.platform.dto.teacher.TeacherQueryDTO;
import com.education.platform.service.TeacherService;
import com.education.platform.vo.teacher.TeacherDetailVO;
import com.education.platform.vo.teacher.TeacherListVO;
import com.education.platform.vo.user.UserIdentityVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "教员管理", description = "教员信息查询、筛选等接口")
@RestController
@RequestMapping("/api/teacher")
@RequiredArgsConstructor
public class TeacherController {

    private final TeacherService teacherService;

    @Operation(summary = "获取教员列表")
    @GetMapping("/list")
    public Result<Map<String, Object>> getTeacherList(TeacherQueryDTO queryDTO) {
        Map<String, Object> result = teacherService.getTeacherList(queryDTO);
        return Result.success(result);
    }

    @Operation(summary = "获取教员详情")
    @GetMapping("/{id}")
    public Result<TeacherDetailVO> getTeacherDetail(@PathVariable Long id) {
        TeacherDetailVO detail = teacherService.getTeacherDetail(id);
        return Result.success(detail);
    }

    @Operation(summary = "获取推荐教员")
    @GetMapping("/recommend")
    public Result<List<TeacherListVO>> getRecommendTeachers(@RequestParam(defaultValue = "10") Integer limit) {
        List<TeacherListVO> list = teacherService.getRecommendTeachers(limit);
        return Result.success(list);
    }

    // ========== 管理员接口 ==========

    @Operation(summary = "管理员查询教员列表")
    @GetMapping("/admin/list")
    @SaCheckLogin
    public Result<Map<String, Object>> adminGetTeachers(AdminTeacherQueryDTO queryDTO) {
        Map<String, Object> result = teacherService.adminGetTeachers(queryDTO);
        return Result.success(result);
    }

    @Operation(summary = "管理员更新教员状态")
    @PostMapping("/admin/{id}/status")
    @SaCheckLogin
    public Result<Void> adminUpdateTeacherStatus(
            @PathVariable Long id,
            @RequestParam String status
    ) {
        teacherService.adminUpdateTeacherStatus(id, status);
        return Result.success();
    }

    @Operation(summary = "获取待审核教员列表")
    @GetMapping("/admin/audit/pending")
    @SaCheckLogin
    public Result<List<Map<String, Object>>> getPendingAuditList() {
        List<Map<String, Object>> list = teacherService.getPendingAuditList();
        return Result.success(list);
    }

    @Operation(summary = "根据状态获取审核列表")
    @GetMapping("/admin/audit/list")
    @SaCheckLogin
    public Result<List<Map<String, Object>>> getAuditListByStatus(@RequestParam String status) {
        List<Map<String, Object>> list = teacherService.getAuditListByStatus(status);
        return Result.success(list);
    }

    @Operation(summary = "审核教员身份")
    @PostMapping("/admin/audit")
    @SaCheckLogin
    public Result<Void> auditTeacherIdentity(@Validated @RequestBody AuditIdentityDTO auditDTO) {
        teacherService.auditTeacherIdentity(auditDTO);
        return Result.success();
    }
}

